/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ravennet.utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;


/**
 *
 * @author Rav
 */
public class RavennetHashMap<K,V> extends HashMap implements Serializable {
    
    private static final long serialVersionUID = 2L;
    
    private int inCurrentKey = 0;
    private ArrayList<String> objOrderedKeyList = new ArrayList<String>();
    
    public RavennetHashMap() {
    }
    
    
    public void put(String key, V value){
        if(!objOrderedKeyList.contains(key)){
            objOrderedKeyList.add(key);    
        }
        super.put(key,value);
    }
    
    public void remove(String key){
        if(objOrderedKeyList.contains(key)){
            objOrderedKeyList.remove(key);
            super.remove(key);
        }
    }
    
    public String[] getKeyArray(){
        return objOrderedKeyList.toArray(new String[0]);
    }
    
    public void resetIterator(){
        inCurrentKey=0;    
    }
    
    public boolean hasNext(){
        if(this.getKeyArray()==null){
            return false;
        }else{
            return inCurrentKey < this.getKeyArray().length;
        }
    }
    
    public V next(){
        if(this.getKeyArray()==null){
            return null;
        }else{
            inCurrentKey++;
            return (V)this.get(this.getKeyArray()[inCurrentKey]);
              
        }
    }
    
    @Override
    public void clear(){
        this.inCurrentKey = 0;
        this.objOrderedKeyList.clear();
        super.clear();
    }
    
}


